package fem2.material.cohesive_law;

import fem2.Element;
import inf.jlinalg.Array2DMatrix;
import inf.jlinalg.ArrayVector;
import inf.jlinalg.IMatrix;
import inf.jlinalg.IVector;

/**
 * cohesive law for pure Mode 1 opening with positive traction and works on
 * positve normal opening
 * 
 * @author hbui
 * 
 */
public class Mode1AbsCohesiveLaw extends CohesiveLaw {

	private double H;
	private double km;

	public Mode1AbsCohesiveLaw(double Gf, double ft, double km) {
		super(Gf, ft);
		H = -Math.pow(ft, 2) / (2 * Gf);
		this.km = km;
	}

	/**
	 * w = [wn wm] with wn - normal jump; wm: tangent jump. <br>
	 * On return, T = [Tn Tm]
	 */
	@Override
	public IVector computeJumpTraction(Element e, IVector w) {
		double tn = ft + H * Math.abs(w.get(0));
		double tm = km * w.get(1);
		return new ArrayVector(Math.max(0.0, tn), tm);
	}

	@Override
	public IMatrix computeJumpStiffness(Element e, IVector w) {
		double tn = ft + H * Math.abs(w.get(0));
		double k = tn < 0.0 ? 0.0 : 1.0;
		double s = w.get(0) >= 0.0 ? 1.0 : -1.0;
		double[][] C = new double[][] { { H * s * k, 0.0 }, { 0.0, km } };
		return new Array2DMatrix(C);
	}

}
